<?php

namespace App\Admin\Actions\Chapter;

use App\Models\Chapter;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;

class RebuildChapterPoster extends RowAction
{
    protected string $title = '更新选手海报';

    public function confirm(): array
    {
        return [
            '确认要更新所有海报么?',
            '一旦确认不可撤销',
        ];
    }

    public function handle(): Response
    {
        $chapter = Chapter::find($this->getKey());

        foreach ($chapter->players as $player) {
            $player->updatePoster();
        }

        return $this->response()
            ->success('批量更新任务提交成功，请稍后下载')
            ->refresh();
    }
}
